package com.chengzhi.netty.handler;

import com.chengzhi.nettycommoms.disruptor.MessageProducer;
import com.chengzhi.nettycommoms.disruptor.RingBufferFactory;
import com.chengzhi.nettycommoms.dto.NettyMessage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        NettyMessage request = (NettyMessage) msg;
/*        Channel channel = ctx.channel();
        request.setMsg("server id --------" + request.getId());
        channel.writeAndFlush(request);*/
        MessageProducer messageProducer = RingBufferFactory.instance().getMessageProducer("server-producerId");
        messageProducer.send(request, ctx);
    }
}
